package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.FansListRequest;
import com.wkhyapp.lm.http.net.PhoneLoginRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.http.vo.Member;

/**
 * Created by fang on 2021/10/30.
 */

public class PhoneLoginPresenter extends BasePresenter<PhoneLoginView>{


    public PhoneLoginPresenter(PhoneLoginView phoneLoginView) {
        super(phoneLoginView);
    }


    public void login(String account,String pwd){
        PhoneLoginRequest request = new PhoneLoginRequest();
        request.setAccount(account);
        request.setPassword(pwd);
        addSubscription(apiStores.login(request),new ApiCallback<SuperResponse<Member>>() {
            @Override
            public void onSuccess(SuperResponse<Member> response) {
                mvpView.loginSucc(response.getItem());
            }
            @Override
            public void onFailure(String msg) {
                mvpView.loginFial(msg);
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void getCode(String account){
        PhoneLoginRequest request = new PhoneLoginRequest();
        request.setPhone(account);
        addSubscription(apiStores.getCode(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.getCode(response.getMessage());
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

    public void codeVer(String account,String code){
        PhoneLoginRequest request = new PhoneLoginRequest();
        request.setPhone(account);
        request.setCode(code);
        addSubscription(apiStores.codeVer(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.verSucc(response.getMessage());
            }
            @Override
            public void onFailure(String msg) {
                mvpView.loginFial(msg);
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

    public void updatePwd(String account,String code){
        PhoneLoginRequest request = new PhoneLoginRequest();
        request.setAccount(account);
        request.setPassword(code);
        addSubscription(apiStores.updatePwd(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.getCode(response.getMessage());
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }
}
